package com.own.component.common.util;

import com.own.component.common.mvc.JacksonObjectMapper;

/**
 * JacksonJsonMapperUtil
 *
 * @author chenxueli
 * @date 2024-03-29 11:50:00
 */
public class JacksonJsonMapperUtil {

    private static JacksonObjectMapper mapper = null;

    /**
     * 将对象转换为json字符串
     *
     * @param object 对象
     * @return json字符串
     */
    public static String toJsonString(Object object) {
        if (mapper == null) {
            mapper = new JacksonObjectMapper();
        }
        try {
            return mapper.writeValueAsString(object);
        } catch (Exception e) {
            throw new RuntimeException("转换json字符串失败", e);
        }
    }

}
